Page({
  data: {
    imagePath: '', // 图片路径
    categories: ['外套', '上衣', '裤子'], // 分类选项
    selectedCategory: '请选择',
    colors: ['黑色系', '白色系', '蓝色系'], // 颜色选项
    selectedColor: '请选择',
    styles: ['休闲', '正式', '运动'], // 风格选项
    selectedStyle: '请选择',
    seasons: ['四季', '春季', '夏季', '秋季', '冬季'], // 季节选项
    selectedSeason: '请选择',
    likes: ['喜欢', '一般', '不喜欢'], // 喜好选项
    selectedLike: '请选择'
  },

  // 选择图片
  chooseImage() {
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success: (res) => {
        const tempFilePath = res.tempFilePaths[0];
        this.setData({
          imagePath: tempFilePath
        });
        // 这里可以调用图片裁剪和抠图的接口
      }
    });
  },

  // 预览图片
  previewImage() {
    wx.previewImage({
      urls: [this.data.imagePath]
    });
  },

  // 分类选择
  bindCategoryChange(e) {
    this.setData({
      selectedCategory: this.data.categories[e.detail.value]
    });
  },

  // 颜色选择
  bindColorChange(e) {
    this.setData({
      selectedColor: this.data.colors[e.detail.value]
    });
  },

  // 风格选择
  bindStyleChange(e) {
    this.setData({
      selectedStyle: this.data.styles[e.detail.value]
    });
  },

  // 季节选择
  bindSeasonChange(e) {
    this.setData({
      selectedSeason: this.data.seasons[e.detail.value]
    });
  },

  // 喜好选择
  bindLikeChange(e) {
    this.setData({
      selectedLike: this.data.likes[e.detail.value]
    });
  },

  // 提交表单
  submitForm() {
    const formData = {
      imagePath: this.data.imagePath,
      category: this.data.selectedCategory,
      color: this.data.selectedColor,
      style: this.data.selectedStyle,
      season: this.data.selectedSeason,
      like: this.data.selectedLike
    };
    // 这里可以调用接口将数据存入MySQL数据库
    wx.request({
      url: 'https://your-server-url.com/submit',
      method: 'POST',
      data: formData,
      success: (res) => {
        wx.showToast({
          title: '提交成功',
          icon: 'success'
        });
      }
    });
  },

  // 清空表单
  clearForm() {
    this.setData({
      imagePath: '',
      selectedCategory: '请选择',
      selectedColor: '请选择',
      selectedStyle: '请选择',
      selectedSeason: '请选择',
      selectedLike: '请选择'
    });
  }
});